import router from '@system.router';
import prompt from '@system.prompt';
import UserApi from '../../api/userApi.js';

export default {
    data: {
        isRead: false,
        isSend: false,
        time: 90,
        phone: '',
        code: '',
        password: '',
        username:'',
    },
    goBack() {
        router.back();
    },
    read() {
        this.isRead = !this.isRead
    },
    getVerificationCode() {
        this.isSend = true;
        prompt.showToast({
            message: '验证码已发送，请注意查收！',
            duration: 3000,
            bottom: '50%'
        });
        var intervalID = setInterval(() => {
            if (this.time > 1) {
                this.time--;
            } else {
                clearInterval(intervalID);
                this.isSend = false;
            }
        }, 1000);
    },
    agree() {
        this.isRead = true;
        this.$element('isReadDialog').close()
    },
    refuse() {
        this.$element('isReadDialog').close()
    },
    init_username(e){
        this.username=e.value;
    },
    init_password(e){
        this.password=e.value;
    },
    register() {
        if (!this.isRead) {
            this.$element('isReadDialog').show();
            return;
        }

        UserApi.register(this.username,this.password,(data) => {
            this.$element('successDialog').show();
        })
    },
    goLogin() {
        router.replace({
            uri: 'pages/login/login'
        });
    },
    cancel(){
        router.replace({
            uri:'pages/main/main'
        });
    }
}
